package com.hh.admin.controller;

import com.hh.common.page.CommonPage;
import com.hh.common.request.PageParamRequest;
import com.hh.common.request.StoreOrderSearchRequest;
import com.hh.common.request.StoreOrderSendRequest;
import com.hh.common.response.CommonResult;
import com.hh.common.response.StoreOrderCountItemResponse;
import com.hh.common.response.integral.IntegralAdminOrderDetailResponse;
import com.hh.service.service.integral.IntegralOrderService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 积分订单
 */
@Slf4j
@RestController
@RequestMapping("api/admin/store/integral/order")
public class StoreIntegralOrderController {

    @Autowired
    private IntegralOrderService integralOrderService;


    /**
     * 分页显示订单表
     *  @param request          搜索条件
     * @param pageParamRequest 分页参数
     */
    @PreAuthorize("hasAuthority('admin:integralOrder:list')")
    @ApiOperation(value = "分页列表") //配合swagger使用
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public CommonResult<CommonPage<IntegralAdminOrderDetailResponse>> getList(@Validated StoreOrderSearchRequest request, @Validated PageParamRequest pageParamRequest) {
        return CommonResult.success(integralOrderService.getAdminList(request, pageParamRequest,false));
    }

    /**
     * 获取订单各状态数量
     */
    @ApiOperation(value = "获取订单各状态数量")
    @RequestMapping(value = "/status/num", method = RequestMethod.GET)
    public CommonResult<StoreOrderCountItemResponse> getOrderStatusNum(
            @RequestParam(value = "dateLimit", defaultValue = "") String dateLimit) {
        return CommonResult.success(integralOrderService.getOrderStatusNum(dateLimit,false));
    }

    /**
     * 订单详情
     */
    @RequestMapping(value = "/info", method = RequestMethod.GET)
    public CommonResult<IntegralAdminOrderDetailResponse> info(@RequestParam(value = "orderNo") String orderNo) {
        return CommonResult.success(integralOrderService.info(orderNo));
    }

    /**
     * 发送货
     */
    @PreAuthorize("hasAuthority('admin:integralOrder:send')")
    @ApiOperation(value = "发送货")
    @RequestMapping(value = "/send", method = RequestMethod.POST)
    public CommonResult<Boolean> send(@RequestBody @Validated StoreOrderSendRequest request) {
        if (integralOrderService.send(request,false)) {
            return CommonResult.success();
        }
        return CommonResult.failed();
    }

}
